package datastructure.array;

import java.util.HashMap;
import java.util.Map;

/**
 * @author XY
 * @version 1.0
 * @date 2022/3/9 9:07
 * @Description
 */
public class Leet219 {

    public static boolean containsNearbyDuplicate(int[] nums, int k) {
        Map<Integer,Integer> map =new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            Integer integer = map.get(nums[i]);
            if(integer!=null&&i-integer <=k){
                return true;
            }
            map.put( nums[i], i);
        }

        return false;
    }

    public static void main(String[] args) {
        int[] arr = {1,0,1,1};
        System.out.println(containsNearbyDuplicate(arr,1));
    }
}
